/**
 * \file Cache.h
 * \brief VM cache.
 * \author Corey Tabaka
 */

/*
   Copyright 2007 Corey Tabaka

   Licensed under the Apache License, Version 2.0 (the "License");
   you may not use this file except in compliance with the License.
   You may obtain a copy of the License at

       http://www.apache.org/licenses/LICENSE-2.0

   Unless required by applicable law or agreed to in writing, software
   distributed under the License is distributed on an "AS IS" BASIS,
   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   See the License for the specific language governing permissions and
   limitations under the License.
*/

#include <ktypes.h>
#include <Reference.h>
#include <Queue.h>
#include <HandleMap.h>

#ifndef __KERNEL_CACHE_H__
#define __KERNEL_CACHE_H__

class Cache;
DEF_REF_TYPE(Cache);

#include <vm/Store.h>
#include <vm/Page.h>
#include <vm/AddressSpace.h>

enum {
	CACHE_OPTIONS_NONE		= 0x0000,
	CACHE_OPTIONS_NOSCAN	= 0x0001,
};

class Cache {
	protected:
	
	RefCache self;
	
	QList regions; // list of regions that refer to this cache
	QList pages; // list of pages in this cache
	
	RefCache cache;
	RefStore store;
	uint32 size; // size of this cache in pages
	
	// pages indexed by offset
	HandleMap<Page *> pageHash;
	
	uint32 options;
	
	public:
	
	Cache(RefStore store, uint32 size, uint32 options=CACHE_OPTIONS_NONE);
	Cache(RefCache cache, uint32 size, uint32 options=CACHE_OPTIONS_NONE);
	~Cache(void);
	
	void insert(Region &region);
	void remove(Region &region);
	
	void insert(Page &page);
	void remove(Page &page);
	
	Page *lookup(offset_t offset);
};

#endif
